<%@page import="com.struts.action.City"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
   
   <%
      List<City> cities=new ArrayList<>();
      cities.add(new City(1001,"AA"));
      cities.add(new City(1002,"BB"));
      cities.add(new City(1003,"CC"));
      cities.add(new City(1004,"DD"));
      request.setAttribute("cities", cities);
   %>


   <!-- 
     1.使用和html的form标签感觉差不多
     2.struts2form标签可以成成一table，进行自动排版
     3.可以对表单提交的值进行回写。从栈顶对象开始匹配属性，并把匹配的属性值赋到对应的标签的value中，若栈顶对象没有对应的属性，
                 则依次向下找相对应的属性。
    -->
   <s:form action="save.action" >
      <s:hidden name="userId"></s:hidden>
      <s:textfield name="username" label="UserName" ></s:textfield>
      <s:password name="password" label="Password"></s:password>
      <s:textarea name="desc" label="Desc"></s:textarea>
      
      <s:radio name="gender" list="#{'1':'Male','0':'Female' }"></s:radio>
      
      <!-- 
                    服务端需要使用集合类型，以能够正常回显 
       -->
      <s:checkboxlist name="city" list="#request.cities"
                      listKey="cityId"
                      listValue="city"
                      label="City"></s:checkboxlist>
      
      <!-- s:select中的list中的值既可以作为键也可以作用值 -->                
      <s:select list="{11,12,13,14,15,16,17,18 }"
                headerKey=""
                headerValue="请选择"
                name="age"
                label="Age">
          <!-- s:optiongroup的list中必须制定key和value -->
          <s:optgroup label="21-30" list="#{21:21}" ></s:optgroup>
          <s:optgroup label="31-40" list="#{31:31}" ></s:optgroup>          
      </s:select>
      
      <s:checkbox name="married" label="Married"></s:checkbox>
      <s:submit></s:submit>
   </s:form>

</body>
</html>